//
// Copyright (C) 2024 Kumo inc.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#pragma once

#include <hadar/hadar.h>
#include <turbo/utility/status.h>
#include <memory>

namespace hadarservice {

    class ConvertEngine {
    public:
        ~ConvertEngine() = default;

        static ConvertEngine &instance();

        turbo::Status initailize(const std::string & dict_path);

        turbo::Result<std::string> hk2s(const std::string & message);

        turbo::Result<std::string> hk2t(const std::string & message);

        turbo::Result<std::string> jp2t(const std::string & message);

        turbo::Result<std::string> s2hk(const std::string & message);

        turbo::Result<std::string> s2t(const std::string & message);


        turbo::Result<std::string> s2tw(const std::string & message);

        turbo::Result<std::string> s2twp(const std::string & message);


        turbo::Result<std::string> t2hk(const std::string & message);

        turbo::Result<std::string> t2jp(const std::string & message);

        turbo::Result<std::string> t2s(const std::string & message);

        turbo::Result<std::string> t2tw(const std::string & message);

        turbo::Result<std::string> tw2s(const std::string & message);

        turbo::Result<std::string> tw2sp(const std::string & message);

        turbo::Result<std::string> tw2t(const std::string & message);
    private:
        ConvertEngine() = default;

        void assert_initialized();
    private:
        std::atomic<bool> initialized_{false};
        std::unique_ptr<hadar::SimpleConverter> hk2s_;
        std::unique_ptr<hadar::SimpleConverter> hk2t_;
        std::unique_ptr<hadar::SimpleConverter> jp2t_;
        std::unique_ptr<hadar::SimpleConverter> s2hk_;
        std::unique_ptr<hadar::SimpleConverter> s2t_;
        std::unique_ptr<hadar::SimpleConverter> s2tw_;
        std::unique_ptr<hadar::SimpleConverter> s2twp_;
        std::unique_ptr<hadar::SimpleConverter> t2hk_;
        std::unique_ptr<hadar::SimpleConverter> t2jp_;
        std::unique_ptr<hadar::SimpleConverter> t2s_;
        std::unique_ptr<hadar::SimpleConverter> t2tw_;
        std::unique_ptr<hadar::SimpleConverter> tw2s_;
        std::unique_ptr<hadar::SimpleConverter> tw2sp_;
        std::unique_ptr<hadar::SimpleConverter> tw2t_;
    };
}  // namespace hadarservice